package two.chapter_1.c1_1;

import edu.princeton.cs.algs4.StdOut;

import java.util.ArrayList;
import java.util.List;

public class Ex1_1_9 {

    /**
     * 十进制转二进制 除2取余法
     * @param args
     */
    public static void main(String [] args){


        //StdOut.println(Integer.toBinaryString(N));
        bookSolution();
        mySolution();

    }
    private static void bookSolution(){
        Integer N=8;
        String s="";
        for (int n=N;n>0;n/=2){
            s=(n%2)+s;
        }
        StdOut.println("bookSolution:"+s);
    }

    private static void mySolution(){
        Integer N=8;
        List<Integer> integers=new ArrayList<>();
        while (N!=0){
            int r=N%2;
            N=N/2;
            integers.add(r);
        }
        StdOut.print("mySolution");
        for (int i=integers.size()-1;i>=0;i--){
            StdOut.print(integers.get(i));
        }
    }

}
